package arithmetic;
/**
 * @author tongchen
 * @create 2023-07-03 13:47
 */
public class NEmpress {
    private static final  int N=8;
    public static int process(int[]data,int i,int n){
        //定义计数器
        int res=0;
        if(i==n){
            return 1;
        }
        //进行递归遍历
        for(int j=0;j<n;++j){
            //判断当前列是否有效
            if(isValid(data,i,j)){
                data[i]=j;
            }
            //递归
          res+=process(data, i+1, n);
            //回溯
            data[i]=0;
        }
        return res;
    }

    private static boolean isValid(int[] data, int i, int j) {
        for(int k=0;k<i;++k){
            if(data[k]==j||Math.abs(i-k)==Math.abs(j-data[k])){
                return false;
            }
        }
        return true;
    }
}
